package business.inhospitalqc;

import com.alibaba.fastjson.JSONObject;
import com.esotericsoftware.yamlbeans.YamlException;
import common.Data;
import common.RunCaseJson;
import common.Yaml;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
import utils.GetFileMess;
import utils.YamlReadUtil;
import java.io.FileNotFoundException;
import static common.Login.login;
import static common.TestStep.requestAndRespondBody;

/*住院质控评价首页-获取质控的历史记录列表信息
* */

public class HistoryList {
    Logger log = Logger.getLogger( HistoryList.class);
    public static final String system = "env.properties";
    Data data = login();

    /**
     *
     * @param i  yml文件的所属classname下的datas数据
     * @return
     * @throws ConfigurationException
     * @throws FileNotFoundException
     * @throws YamlException
     */
    public String GetHistoryList(int i) throws ConfigurationException, FileNotFoundException, YamlException {
        String path=new GetFileMess().getValue("ymlPath",system);
        Yaml yaml=YamlReadUtil.getLocatorMap(path,this.getClass().getName());
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("relatedUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("diseaseCode", yaml.getDatas().get(i).get("diseaseCode"));     // 病种
        json.put("page", yaml.getDatas().get(i).get("page"));
        json.put("size", yaml.getDatas().get(i).get("size"));
        json.put("types", yaml.getDatas().get(i).get("types"));          //图表类型：1=copd，2=aecopd，3=指标检测图
        json.put("checkFlag", yaml.getDatas().get(i).get("checkFlag"));   //审核标志：0=未审核，1=已审核
        Response response = RunCaseJson.runCase(json, "get",yaml.getUri());
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        String url = RestAssured.baseURI + ":" + RestAssured.port + yaml.getUri();
        requestAndRespondBody(url, json, jsonStr);
        return jsonStr;
    }

    /**
    * @Description:
     * @param diseaseCode	病种 eg.copd、ASTHMA
     * @param checkFlag	 审核标志：0=未审核，1=已审核
     * @param uri	api-sourcedata/qc/batch/patient/list.json
    * @return java.lang.String
    * @author gujinle
    * @date 2021-08-23 16:44
    */

    public String GetHistoryList(String diseaseCode,String checkFlag,String uri) {
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("relatedUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("diseaseCode", diseaseCode);     // 病种
        json.put("page", "1");
        json.put("size", "10000");
        json.put("types", "1");          //图表类型：1=copd，2=aecopd，3=指标检测图
        json.put("checkFlag", checkFlag);   //审核标志：0=未审核，1=已审核
        Response response = RunCaseJson.runCase(json, "get",uri);
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        return jsonStr;
    }

    public static void main(String[] args) throws ConfigurationException, FileNotFoundException, YamlException {
        String path=new GetFileMess().getValue("ymlPath",system);
        Yaml yaml=YamlReadUtil.getLocatorMap(path,"business.inhospitalqc.HistoryList");
        for (int i=0;i<yaml.getDatas().size();i++) {
            String diseaseCode=yaml.getDatas().get(i).get("diseaseCode").toString();
        }


    }
}
